package com.uiao.stone.controller;

import com.uiao.stone.common.config.ConfigBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Timer;

/**
 * 测试一些application配置的使用
 * Created by Administrator on 2017/9/19.
 */
@Controller
@RequestMapping(value = "goods", method = RequestMethod.GET)
public class GoodController {

    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(GoodController.class);

    @Autowired
    ConfigBean configBean;
    @Value("${com.stone.me}")
    private String me;

    @GetMapping("mybooklist")
    public String show(HttpServletRequest request) {
        String bookType = "科幻";
        request.setAttribute("key", "这是一个页面");
        request.setAttribute("booktype", bookType);
        request.setAttribute("me", me);
        System.out.println("测试热部署");
        logger.debug("这是一条debug级别的日志啊");
        logger.info("这是一条info级别的日志");
        logger.error("这是一条error级别的日志");
        return "goods/goodlist";
    }

    @GetMapping("bookdetail")
    public @ResponseBody String show2() {
        try {
            Thread.sleep(2000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        System.out.println("执行bookdetail");
        //configBean.setAddress("日照市");
        return "鸡年大吉" + me;
    }

    /*
    *  每天凌晨01：00执行一次
    * */
    //@Scheduled(cron = "0 0 1 * * *")
    public void MyTask1() {
        System.out.println(new Timer().toString());
    }

    /*
    * 每五秒执行一次
    * */
    //@Scheduled(fixedRate = 1000 * 50)
    public void MyTask2() {
        System.out.println(new Date() + "每50秒就会执行一次");
    }

}
